package com.huazi.www.doctor.hu.service.impl;


import com.huazi.util.SessionUtil;
import com.huazi.www.doctor.doctorg.dao.QueueDao;
import com.huazi.www.doctor.hu.dao.DoctorDao;
import com.huazi.www.doctor.hu.dao.impl.DoctorDaoImpl;
import com.huazi.www.doctor.hu.entity.*;
import com.huazi.www.doctor.hu.page.Page;
import com.huazi.www.doctor.hu.service.DoctorService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class DoctorServiceImpl implements DoctorService {
    DoctorDao dao = new DoctorDaoImpl();
    SqlSession session = SessionUtil.getSession();
    DoctorDao mapper = session.getMapper(DoctorDao.class);

    /**
     * 判断是否有CT记录
     *
     * @param no
     * @return
     */
    @Override
    public boolean selCtCount(Integer no) {

        int i = mapper.selCtCount(no);
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean selDiCount(Integer no) {
        int i = mapper.selDiCount(no);
        if (i > 0) {
            return true;
        }
        return false;
    }

    /**
     * 获取CT结果
     *
     * @param no
     * @return
     */
    @Override
    public List<CtInfo> selCt(Integer no) {
        return mapper.selCt(no);
    }

    /**
     * 查询以往病例
     *
     * @param no
     * @return
     */
    @Override
    public List<DiseaseInfo> selDisease(Integer no) {
        return mapper.selDisease(no);
    }

    /**
     * 获取病人信息
     *
     * @param currentPage
     * @return
     */
    @Override
    public Page<PatientInfo> selPat(Integer currentPage, Integer doctorId) {
        Page<PatientInfo> page = new Page<>();
        DoctorDao dao = new DoctorDaoImpl();
        page.setCurrentPage(currentPage);
        page.setPageSize(20);
        int count = dao.totalCount();
        page.setTotalCount(count);
        int start = (page.getCurrentPage() - 1) * page.getPageSize();
        List<PatientInfo> select = dao.selPat(start, page.getPageSize(), doctorId);
        page.setList(select);
        return page;
    }

    /**
     * 得到药品的集合
     *
     * @return
     */
    public List<Drug> list() {
        return mapper.listdrug();
    }

    /**
     * 插入药单
     *
     * @param list
     * @param bingli
     */
    public void insertlist(List<Medicine> list, String bingli) {

        dao.druglist(list, bingli);

    }

    public boolean checkinsert(int id) {
        int boo = mapper.usercheckselect(id);
        if (boo > 0) {
            return true;
        }
        return false;
    }


}
